package hn.sigit.model.ladm.party;

import java.io.Serializable;
import javax.persistence.*;

import org.hibernate.annotations.Columns;
import org.hibernate.annotations.Type;
@Entity
@org.hibernate.annotations.Proxy(lazy=false)
@Table(name="LA_PartyMember", schema="ladm_party")
@Inheritance(strategy=InheritanceType.JOINED)
@IdClass(LA_PartyMemberPK.class)
public class LA_PartyMember extends hn.sigit.model.ladm.special.VersionedObject implements Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private long la_partyId;
	private long la_grouppartyId;
	private LA_GroupParty la_groupparty;
	private LA_Party la_party;
	private hn.sigit.model.ladm.special.Rational share;

	public LA_PartyMember() {
	}

	
	@Id
	@Column(name="LA_PartyID", nullable=false)
	@GeneratedValue(generator="la_partymember_gen")
	@org.hibernate.annotations.GenericGenerator(name="la_partymember_gen", strategy="foreign", parameters=@org.hibernate.annotations.Parameter(name="property", value="Id"))
	public long getLa_partyId() {
		return la_partyId;
	}
	protected void setLa_partyId(long value) {
		this.la_partyId = value;
	}
	
	@Id
	@Column(name="LA_GroupPartyLA_PartyID", nullable=false)
	@GeneratedValue(generator="la_partymember_gen2")
	@org.hibernate.annotations.GenericGenerator(name="la_partymember_gen2", strategy="foreign", parameters=@org.hibernate.annotations.Parameter(name="property", value="Id"))
	public long getLa_grouppartyId() {
		return la_grouppartyId;
	}
	protected void setLa_grouppartyId(long value) {
		this.la_grouppartyId = value;
	}
	
	@Type(type = "hn.sigit.model.ladm.special.RationalUserType")
	@Columns(columns = {
			@Column(name = "share_numerator"),
			@Column(name = "share_denominator")
	})
	public hn.sigit.model.ladm.special.Rational getShare() {
		return share;
	}
	public void setShare(hn.sigit.model.ladm.special.Rational value) {
		this.share = value;
	}
	
	@PrimaryKeyJoinColumn
	@ManyToOne(targetEntity=LA_GroupParty.class)
	@org.hibernate.annotations.Cascade({org.hibernate.annotations.CascadeType.LOCK})
	@JoinColumns({ @JoinColumn(name="LA_GroupPartyLA_PartyID", referencedColumnName="LA_PartyID") })
	public LA_GroupParty getLa_groupparty() {
		return la_groupparty;
	}
	public void setLa_groupparty(LA_GroupParty value) {
		this.la_groupparty = value;
	}
	
	@PrimaryKeyJoinColumn
	@ManyToOne(targetEntity=LA_Party.class)
	@org.hibernate.annotations.Cascade({org.hibernate.annotations.CascadeType.LOCK})
	@JoinColumns({ @JoinColumn(name="LA_PartyID", referencedColumnName="ID") })
	public LA_Party getLa_party() {
		return la_party;
	}
	public void setLa_party(LA_Party value) {
		this.la_party = value;
	}
	

	
	public boolean equals(Object aObj) {
		if (aObj == this)
			return true;
		if (!(aObj instanceof LA_PartyMember))
			return false;
		LA_PartyMember la_partymember = (LA_PartyMember)aObj;
		if (getLa_party() == null) {
			if (la_partymember.getLa_party() != null)
				return false;
		}
		else if (!getLa_party().equals(la_partymember.getLa_party()))
			return false;
		if (getLa_groupparty() == null) {
			if (la_partymember.getLa_groupparty() != null)
				return false;
		}
		else if (!getLa_groupparty().equals(la_partymember.getLa_groupparty()))
			return false;
		return true;
	}
	
	public int hashCode() {
		int hashcode = 0;
		if (getLa_party() != null) {
			hashcode = hashcode + (int) getLa_party().getORMID();
		}
		if (getLa_groupparty() != null) {
			hashcode = hashcode + (int) getLa_groupparty().getORMID();
		}
		return hashcode;
	}
	
	
	public String toString() {
		return super.toString();
	}
	
	private boolean _saved = false;
	
	public void onSave() {
		_saved=true;
	}
	
	
	public void onLoad() {
		_saved=true;
	}
	
	
	@Transient
	public boolean isSaved() {
		return _saved;
	}
	
	
}
